// i.r(t), i.d(t, { default: () => SweepPinNavigation })
import Module from "./Module"
import SweepPinMeshModules from "./SweepPinMeshModule"
import { SetMouseCursorCommand } from "../command/cursor.command"

import ViewmodeModule from "./ViewmodeModule"
import ViewmodeData from "../data/ViewmodeData"
import * as THREE from "three"
import Comparator from "../utils/Comparator"
import SymbolList from "../SymbolList"

import cursorEnum from "../enum/cursor.enum"
import PinCollider from "../mesh/PinCollider"
import { ClickEvent, HoverEvent, UnhoverEvent } from "../event/GestureEvent"
import viewmodeEnum from "../enum/viewmode.enum"
import transitionTypeEnum from "../enum/transitionType.enum"
export default class SweepPinNavigation extends Module {
  constructor() {
    super(...arguments), (this.name = "sweep-pin-navigation")
  }
  async init(e, t) {
    const [i, n, v, y] = await Promise.all([
        t.getModule(SweepPinMeshModules),
        t.getModule(ViewmodeModule),
        t.market.waitForData(ViewmodeData),
        t.getModuleBySymbol(SymbolList.INPUT)
      ]),
      b = new THREE.Quaternion()
    this.bindings.push(
      y.registerMeshHandler(ClickEvent, Comparator.isType(PinCollider), (e, t, s) => {
        const r = i.mapColliderToSweep(t)
        return (
          !(!r || v.transition.active) &&
          (b.set(0, 0, 0, 1).multiply(r.rotation),
          (o = r.id),
          (a = b),
          v.currentMode &&
            v.currentMode !== viewmodeEnum.Panorama &&
            n.switchToMode(viewmodeEnum.Panorama, transitionTypeEnum.FadeToBlack, {
              sweepID: o,
              rotation: a
            }),
          !0)
        )
        var o, a
      }),
      y.registerMeshHandler(HoverEvent, Comparator.isType(PinCollider), (e, n) => {
        i.mapColliderToSweep(n) && t.commandBinder.issueCommand(new SetMouseCursorCommand(cursorEnum.FINGER))
      }),
      y.registerMeshHandler(UnhoverEvent, Comparator.isType(PinCollider), (e, n) => {
        i.mapColliderToSweep(n) && t.commandBinder.issueCommand(new SetMouseCursorCommand(null))
      })
    )
  }
}
